#!/usr/bin/env bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

set -e

GIT_ROOT="$(git rev-parse --show-toplevel)"
pushd $GIT_ROOT >/dev/null
# TODO: if this check is too slow at some future point, incremental
# checking can be done with eg.
# `$(git diff --cached --name-only --diff-filter=ACMR "*.js" "*.jsx" |
#    sed 's| |\\ |g')`
for f in $(find -type f -name 'Cargo.toml'); do
  pushd $(dirname $f) >/dev/null
  cargo-fmt -- --check
  cargo-clippy
  popd >/dev/null
done
popd >/dev/null

